//
//  HJUserModel.m
//  KaiChat
//
//  Created by lx on 2023/12/18.
//

#import "HJUserModel.h"

@implementation HJUserModel

MJLogAllIvars


+ (NSArray *)bg_uniqueKeys {
    return @[@"userId"];
}

- (NSString *)bg_tableName {//因为之前使用的是email作为唯一主键, 现在换个表名
    return [NSString stringWithFormat:@"kai_%@", NSStringFromClass(self.class)];
}

+ (NSString *)bg_tableName {
    return [NSString stringWithFormat:@"kai_%@", NSStringFromClass(self.class)];
}

+ (HJUserModel *)modelWithBlock:(void (^)(HJUserModel *model))block {
    HJUserModel *model = [[HJUserModel alloc] init];
    if (block) block(model);
    return model;
}

+ (HJUserModel *)modelWithUserId:(NSString *)userId {
    HJUserModel *userModel = [HJUserModel bg_find:[HJUserModel bg_tableName] where:[NSString stringWithFormat:@"where %@=%@", bg_sqlKey(@"userId"), bg_sqlValue(userId)]].firstObject;
    if (!userModel) {
        userModel = [[HJUserModel alloc] init];
        userModel.userId = userId;
        userModel.mineTabBarItemRead = NO;
        userModel.accountSecurityRead = NO;
        userModel.bindGoogleRead = NO;
        userModel.bindAppleRead = NO;
        userModel.noticeOpen = YES;
        userModel.noticePreview = YES;
        userModel.noticeSound = YES;
        userModel.noticeVibration = YES;
        [userModel bg_saveOrUpdateAsync:nil];
    }
    return userModel;
}

+ (HJUserModel *)currentAccountModel {
    return [self modelWithUserId:HJUserInfo.userId];
}

@end
